import { App, toRefs } from 'vue'
import { userMenuListStore } from '@/store/index'
/**
 * {params:binding}: 传入进来的值
 * {params:el}: 实例
 */
export const regPermission = (app: App<Element>) => {
  const AppStore = userMenuListStore()
  const { btnList } = toRefs(AppStore)
  app.directive('permission', {
    mounted(el: any, binding: any) {
      console.log(binding, 'binding')
      const hasPermission = AppStore.btnList.some((item: any) => {
        return item.includes(binding.value)
      })
      if (!hasPermission) {
        el.parentNode?.removeChild(el)
      }
      console.log(hasPermission, 'hasPermission----------')
    },
  })
}
